/* @update: 2016-10-27 13:34:34 */
var Cube = {
    config: {
        prefix: "cube"
    },
    rowZIndex: 180,
    getRowZIndex: function() {
        return Cube.rowZIndex -= 1
    }
};
$( function() {
    var e = Cube.config;
    $.fn.select = function(t) {
        return t = $.extend({
            callback: null ,
            ajaxUrl: "",
            dataType: "json"
        }, t),
            this.each(function() {
                function a(t) {
                    for (var a = 0, i = t.length; i > a; a++)
                        c.push("<li " + e.prefix + "-data=" + t[a].value + ">"),
                            c.push("<a href=javascript:void(0);>" + t[a].name + "</a>"),
                            c.push("</li>");
                    l.html(c.join(""))
                }
                var i = $(this)
                    , l = $("[" + e.prefix + "-type=cont]", i)
                    , c = [];
                i.parent().css({
                    zIndex: Cube.getRowZIndex()
                }),
                t.ajaxUrl.length && !function(e) {
                    $.ajax({
                        url: t.ajaxUrl,
                        dataType: t.dataType,
                        success: function(t) {
                            var a = t.data;
                            e(a)
                        }
                    })
                }(a),
                    i.find("[" + e.prefix + "-type=title], s").on("click.select", function() {
                        l.css({"zIndex":99999,"paddingLeft":0}),
                            l.not(":visible") ? (l.find("li").length > 5 && l.css({
                                display: "block",
                                height: 5 * l.find("li").eq(0).outerHeight() + "px",
                                "overflow-y": "scroll"
                            }),
                                i.addClass("cu-select-active")) : (i.removeClass("cu-select-active"),
                                l.removeAttr("style"))
                    }),
                    i.on("mouseleave.select", function() {
                        i.removeClass("cu-select-active"),
                            l.removeAttr("style")
                    }),
                    i.on("click.select", "li", function() {
                        var a = $(this).attr("" + e.prefix + "-data");
                        i.find("[" + e.prefix + "-type=title]").text($(this).text()).end().find(":hidden").val(a),
                            i.removeClass("cu-select-active").find(".cu-form-prompt").removeClass("animation"),
                            l.removeAttr("style"),
                        $.isFunction(t.callback) && t.callback.call(this, a)
                    })
            })
    }
});
